import React,{Component} from 'react'
import rootStore from "./src/mobx/index";
import { Provider} from "mobx-react";
import{View} from 'react-native'
import AsyncStorage from "@react-native-community/async-storage"
import Nav from './src/pages/nav'
import { createStackNavigator } from '@react-navigation/stack';
const Stack = createStackNavigator();
import Geo from './src/utils/Geo'
class App extends Component {
    state={
        isInitGeo:false
    }
    async componentDidMount(){
        const strUserInfo = await AsyncStorage.getItem('userInfo')
        //获取缓存中的用户数据
        const userInfo = strUserInfo?JSON.parse(strUserInfo):{}
        // 判断userInfo有没有token
        console.log("userInfo=",userInfo)
        if(userInfo.token){
            //把缓存中的数据存一份到mobx中
            rootStore.setUserInfo(userInfo.mobile,userInfo.token,userInfo.userId)
        }
        await Geo.initGeo()
        this.setState({isInitGeo:true})
    }
    render() { 
        
        const {isInitGeo} = this.state
        return ( 
            <Provider rootStore={rootStore}>
                <View style={{flex:1}}>
                    {isInitGeo?<Nav></Nav>:<></>}
                </View>
            </Provider>
         );
    }
}
 
export default App;